import {Balance, Withdraw} from '../../../Common/';

module.exports = {
    name: 'account',
    data(){
    	return{
          userAccount: 0,
          records: [],
          currentPage: 1,
          total: 0,
          page: 1,
          size: 3,
          balanceMenu: [{
              text: '提现',
              command: 'withdraw'
          }, {
              text: '修改密码',
              command: 'modify'
          }],
          withdrawVisible: false,
          tipsVisible: false,
          infoVisible: false,
          valiInfo: []
    	}
    },
    components: {
        Balance,
        Withdraw
    },
    methods: {
        /**
         * 获取交易记录
         */
        getRecords() {
            let data = this.$$formData({
                water_store_id: '',
                page: this.page,
                size: this.size
            })
            this.$$api_manager_record(data, res => {
                if(res.event === 0) {
                    this.records = res.obj
                    this.total = res.maxCount;
                }else {
                    cbs.submitError.call(this, `交易记录获取失败，${res.msg}`);
                }
            })

        },
        /**
         * 改变当前页数
         */
        handleCurrentChange(v) {
            this.page = v;
            this.getRecords();
        },
        /**
         * 提现
         */
        onWithdraw() {
            this.hasPayPwd ? this.withdrawVisible = true : this.tipsVisible = true;
        },
        /**
         * 修改支付密码
         */
        onModify() {
            this.$router.push('/account/modifyPwd/pay');
        },
        /**
         * 关闭提现窗口前
         */
        closeWithdraw() {
          this.withdrawVisible = false;
          this.$refs.withdraw.onClose()
        },
        /**
         * 展示认证信息
         */
        onShowInof() {
          this.infoVisible = true;
        }
    },
    mounted() {  
        this.$refs.balance.getBalance();
        this.getRecords();
        $('.dialog-withdraw .el-dialog').css('width', '340px');
    },
    computed: {
        hasPayPwd() {
          return this.$store.state.user.userinfo.hasPay;
        }
    }
}